import java.io.*;
import java.text.*;
import java.math.*;
import java.util.*;

public class Cinema2 implements Runnable {

    final static String taskname = "filename";

    public void solve() throws Exception {
    	String input[] = in.readLine().split(" +");
    	int n = Integer.parseInt(input[0]);
    	int m = Integer.parseInt(input[1]);	
    	int k = Integer.parseInt(input[2]);
    	
    	boolean [][] places = new boolean[n][m];
    	
    	int [][] hasNextEmpty = new int[n][m];
    	
    	for (int i=0; i<n ; i++) 
    		{for ( int j=0; j<m; j++)
    			{hasNextEmpty[i][j] = 4;  places[i][j] = true;}}
    	
    	
    	
    	for ( int i =0 ; i < k; i++){
    		input = in.readLine().split(" +");
    		
    		int x = Integer.parseInt(input[0])-1;
    		int y = Integer.parseInt(input[1])-1;
    		
    		int[] nextX = new int[n*m];
    		int[] nextY = new int[n*m];
    		
    		int current = 0;
    		int end = 0;
    		boolean [][] inQueue = new boolean[n][m];
    		boolean flag = false;
    		    		
    		while (!flag) {  
    		if ( places[x][y] ) {
    			
    			places[x][y] = false;
    			
    			/*if ( x-1 >=0)    hasNextEmpty[x-1][y] --;
    			if ( y-1 >= 0)    hasNextEmpty[x][y-1] --;
    			if ( y+1 <= m-1) hasNextEmpty[x][y+1] --;
    			if (x+1 <= n-1)  hasNextEmpty[x+1][y] --;  */
    			
    			
    			
    			out.write( (x + 1) +" "+ (y+1)+"\n" );
    			flag = true;
    		    			
    		}
    		
    		else {
    			if ( (x-1>=0)  && (!inQueue[x-1][y])) {  nextX[end] = x-1; nextY[end] = y; inQueue[x-1][y] = true; end++;}
    			if ( (y-1>=0)&& (!inQueue[x][y-1]) ) {  nextX[end] = x; nextY[end] = y-1; inQueue[x][y-1] = true;  end++;}
    			if ( (y+1<=m-1)  && (!inQueue[x][y+1])) {  nextX[end] = x; nextY[end] = y+1;inQueue[x][y+1] = true; end++;}
    			if ( (x+1<=n-1) && (!inQueue[x+1][y])) {  nextX[end] = x+1; nextY[end] =y; inQueue[x+1][y] = true;end++;}
    			    			
    			x = nextX[current];
    			y = nextY[current];
    			current++;
    			
    			
    		}
    		
    		}
    		
    		
    	}
    	
    	
    	
    	
    	
    //	out.write(ans + "\n");
    //    out.write(ans_path + "\n");
    }

    public void run() {
        try {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new BufferedWriter(new OutputStreamWriter(System.out));
//             in = new BufferedReader(new FileReader(taskname + ".in"));
//             out = new BufferedWriter(new FileWriter(taskname + ".out"));
            solve();
            out.flush();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    public int iread() throws Exception {
        return Integer.parseInt(readword());
    }

    public double dread() throws Exception {
        return Double.parseDouble(readword());
    }

    public long lread() throws Exception {
        return Long.parseLong(readword());
    }

    BufferedReader in;

    BufferedWriter out;

    public String readword() throws IOException {
        StringBuilder b = new StringBuilder();
        int c;
        c = in.read();
        while (c >= 0 && c <= ' ')
            c = in.read();
        if (c < 0)
            return "";
        while (c > ' ') {
            b.append((char) c);
            c = in.read();
        }
        return b.toString();
    }

    public static void main(String[] args) {
        // Locale.setDefault(Locale.US);
        new Thread(new Cinema2()).start();
    }
}